import React from 'react';
import NVD3Chart from 'react-nvd3';
import { API_SERVER,stockname } from './../../../../config/constant';
import axios from 'axios';
const sin=[] ;
const time=[] ;

function getDatum2() {


    axios.post(API_SERVER + 'stocks/getdata', {
            "stockname":stockname
        })
        .then(function (response) {      
            for (var i = 0; i < response.data.data.length; i++) {
                sin.push({
                    x: i,
                    y: response.data.data[i]
                });
                time.push(response.data.time[i]);

            }
            if (response.data.success) {
                console.log(response.data);
                //alert(response.data)
                this.forceUpdate();
            }
        })
        .catch(function (error) {
            console.log(error);
        });
            
    return [
        {
            values: sin,
            key: stockname,
            color: '#1de9a6',
            area: true
        }
    ];
}
const data = getDatum2();

const LineChart =(async) => {
    return (
        <React.Fragment >
            {React.createElement(NVD3Chart, {
                xAxis: {
                    tickFormat: function (s) {
                        return time[s];
                    },
                    axisLabel: '时间'
                },
                yAxis: {
                    axisLabel: '价格',
                    tickFormat: function (d) {
                        return parseFloat(d).toFixed(2);
                    }
                },
                type: 'lineChart',
                datum: data,
                x: 'x',
                y: 'y',
                height: 300,
                renderEnd: function () {
                    console.log('renderEnd');
                }
            })}
        </React.Fragment>
    );
};

export default LineChart;
